package keeto.com.vn.bms.network.task;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;

import keeto.com.vn.bms.config.IBMSCore;
import keeto.com.vn.bms.network.request.SendMessegerRequest;
import keeto.com.vn.bms.network.response.SendMessegerResponse;
import keeto.com.vn.bms.utils.BMSListener;

public class TaskSendMesseger extends AbstractTask{

	private String UserId;
	private String Tittle;
	private String Content;
	private String AuthKey;
	private String GroupId;


	
	public TaskSendMesseger(BMSListener listener, IBMSCore core, String userId,
			String tittle, String content, String authKey, String groupId) {
		super(listener, core);
		this.UserId = userId;
		this.Tittle = tittle;
		this.Content = content;
		this.AuthKey = authKey;
		this.GroupId = groupId;
	}

	
	@Override
	public void run() throws ClientProtocolException, JSONException,
	IOException {
		// TODO Auto-generated method stub
		SendMessegerRequest request = new SendMessegerRequest();
		request.setUserId(UserId);
		request.setTittle(Tittle);
		request.setContent(Content);
		request.setAuthKey(AuthKey);
		request.setGroupId(GroupId);
		SendMessegerResponse response = protocol.sendMesseger(request);
		for (BMSListener mlistener : listener){
			mlistener.finishSendMesseger(response.getReturnCode(), response.getResuiltMsg(),response.getIdMsg());
		}

	}

	@Override
	public void timeoutCallback() {
		// TODO Auto-generated method stub
		for (BMSListener mlistener : listener){
			mlistener.finishSendMesseger(protocol.STATUS_CODE_GENERIC_FAIL_CONECTTION, null,null);
		}
	}

}
